package net.lym.strategy;

import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import net.lym.entity.MerchandiseEntity;
import net.lym.entity.UserEntity;
import net.lym.enums.DiscountEnum;
import net.lym.strategy.context.ShoppingStrategyAware;
import org.springframework.stereotype.Component;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * 至尊vip策略
 */
@Slf4j
@Component
public class EVIPStrategy implements ShoppingStrategyAware {
    @Override
    public DiscountEnum getStrategy() {
        log.info("load strategy: {}", JSON.toJSONString(DiscountEnum.EVIP));
        return DiscountEnum.EVIP;
    }

    @Override
    public Map<String, Object> buy(UserEntity user, MerchandiseEntity merchandise) {
        log.info("current strategy: {}", getStrategy().getType());
        DecimalFormat df = new DecimalFormat("0.00");
        Map<String, Object> result = new HashMap<>();
        result.put("用户姓名", user.getName());
        result.put("用户性别", user.getGender());
        result.put("用户年龄", user.getAge());
        result.put("用户等级", getStrategy().getType());
        result.put("商品名称", merchandise.getName());
        result.put("商品原价", df.format(merchandise.getPrice()));
        result.put("应享折扣", df.format(getStrategy().getDiscount()));
        result.put("折后价格", df.format(merchandise.getPrice().multiply(getStrategy().getDiscount())));
        return result;
    }

}
